package com.ruoyi.canteen.mapper;

import java.util.List;
import com.ruoyi.canteen.domain.CanteenCpOrderDetail;
import com.ruoyi.canteen.vo.CanteenOrderItemVo;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * 订单明细Mapper接口
 * 
 * @author zhangw
 * @date 2021-09-19
 */
public interface CanteenCpOrderDetailMapper 
{
    /**
     * 查询订单明细
     * 
     * @param id 订单明细主键
     * @return 订单明细
     */
    public CanteenCpOrderDetail selectCanteenCpOrderDetailById(Long id);

    /**
     * 查询订单明细列表
     * 
     * @param canteenCpOrderDetail 订单明细
     * @return 订单明细集合
     */
    public List<CanteenCpOrderDetail> selectCanteenCpOrderDetailList(CanteenCpOrderDetail canteenCpOrderDetail);

    /**
     * 新增订单明细
     * 
     * @param canteenCpOrderDetail 订单明细
     * @return 结果
     */
    public int insertCanteenCpOrderDetail(CanteenCpOrderDetail canteenCpOrderDetail);

    /**
     * 修改订单明细
     * 
     * @param canteenCpOrderDetail 订单明细
     * @return 结果
     */
    public int updateCanteenCpOrderDetail(CanteenCpOrderDetail canteenCpOrderDetail);

    /**
     * 删除订单明细
     * 
     * @param id 订单明细主键
     * @return 结果
     */
    public int deleteCanteenCpOrderDetailById(Long id);

    /**
     * 批量删除订单明细
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteCanteenCpOrderDetailByIds(Long[] ids);

    /**
     * 通过主订单id，查询子订单详情
     * @param orderId
     * @return
     */
    @Select("SELECT d.id as detail_id,d.order_id,d.order_no,d.md_id,spec," +
            "p.id as cp_id,price,amount,cp_sum,name,url from canteen_cp_order_detail as d " +
            "left join canteen_cp as p on d.cp_id = p.id " +
            "where d.order_id= #{orderId}")
    @Results({
            @Result(property = "id",column = "detail_id"),
            @Result(property = "orderId",column = "order_id"),
            @Result(property = "cpId",column = "cpId"),
            @Result(property = "mdId",column = "md_id"),
            @Result(property = "name",column = "name"),
            @Result(property = "price",column = "price"),
            @Result(property = "spec",column = "spec"),
            @Result(property = "number",column = "amount"),
            @Result(property = "cpSum",column = "cp_sum"),
            @Result(property = "cpPic",column = "url")
    })
    public List<CanteenOrderItemVo> selectOrderDetailListByOrderId(Long orderId);

}
